from enum import Enum


class MinuteEnum(Enum):
    ValTwo = ((30, '1'))
    ValOne = ((0, '0'))

    def __init__(self, val, ret):
        self.val = val
        self.ret = ret

    @staticmethod
    def getval(minute):
        for v in MinuteEnum:
            if minute >= v.val:
                return v.ret
        return None


class HourEnum(Enum):
    ValOne = ((9, '1'))
    ValTwo = ((10, '2'))
    VALTHREE = ((11, '3'))

    VALFour = ((13, '4'))
    VALFIVE = ((14, '5'))
    VALSIX = ((15, '6'))

    def __init__(self, val, ret):
        self.val = val
        self.ret = ret

    @staticmethod
    def getval(value):
        for v in HourEnum:
            if value == v.val:
                return v.ret
        return None


class OrderStateEnum(Enum):
    '''
    订单状态（-2-过期作废；-1-取消：0-新建；1-部分完成；2-已完成）
    '''

    TIMEOUT_CANCEL = ((-2, '订单超时取消'))
    CANCEL = ((-1, '取消'))
    NEW_BUILT = ((0, '新建'))
    PARTIALLY_COMPLETED = ((1, '部分完成'))
    COMPLETED = ((2, '已完成'))

    def __init__(self, code, msg):
        self.code = code
        self.msg = msg


class DealDirectionEnum(Enum):
    '''
    交易方向1：买入，-1：卖出  0:不操作
    '''
    BUY = ((1, '买入'))
    SELL = ((-1, '卖出'))
    NONE = ((0, '不操作'))

    def __init__(self, code, msg):
        self.code = code
        self.msg = msg


class TrendEnum(Enum):
    '''
    趋势枚举  -3：暴跌；-2：下降；-1：波动；0：转折点；1：平稳；2：上升；3：暴力拉升
    '''

    PLUMMET = ((-3, '暴跌'))
    DOWN = ((-2, '下降'))
    WAVE = ((-1, '波动'))
    TURNING_POINT = ((0, '转折点'))
    STABLE = ((1, '平稳'))
    UP = ((2, '上升'))
    PROMOTION = ((3, '暴力拉升'))

    def __init__(self, code, msg):
        self.code = code
        self.msg = msg

    def is_transverse(self):
        '''
        是否横盘
        '''
        return self == TrendEnum.WAVE or self == TrendEnum.STABLE

    def is_up(self):
        '''
        是否上涨
        '''
        return self == TrendEnum.UP

    def is_down(self):
        '''
        是否下降
        '''
        return self == TrendEnum.DOWN


class LifelineTypeEnum(Enum):
    '''
    生命线类型    0---水平线  1--- 斜线
    '''
    HORIZON = 0
    slant = 1

    def __init__(self, code):
        self.code = code


class LineModeEnum(Enum):
    '''
    生命线模式（0-手动添加，1-放量大涨，2-放量大跌，3-顶部，4-底部）
    '''

    MANUAL = 0
    INCREASE = 1
    DECLINE = 2
    TOP = 3
    BOTTOM = 4

    def __init__(self, code):
        self.code = code

class LinePositionEnum(Enum):
    '''
    价格和生命线位置（0- 胶着（生命线范围内），1- 涨破，2- 回调（反弹），3-跌破，4-远离）
    '''
    PRESSURE=((0,'压力'))
    RISE = ((1,'涨破'))
    SUPPORT=((2,'支撑'))
    FALL = ((3,'跌破'))
    BACK = ((4,'回调'))
    FAR_AWAY = ((5,'远离'))

    def __init__(self, code, msg):
        self.code = code
        self.msg = msg
